package backstage.information.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import backstage.information.dao.InformationDao;
import backstage.information.pojo.Information;
import backstage.information.service.InformationService;
import backstage.staff.pojo.Staff;

public class InformationServiceImpl implements InformationService{

	private InformationDao informationDao;
	
	public List<Information> getInformation(List<Information> list) {
		List<Information> all = new ArrayList<Information>();
		List<Information> error = new ArrayList<Information>();
		List<Information> other = new ArrayList<Information>();
		for (Iterator<Information> iterator = list.iterator(); iterator.hasNext();) {
			Information information = iterator.next();
			if(information.getStatus() == 1){
				if("error".equals(information.getInfotype())){
					error.add(information);
				}else{
					other.add(information);
				}
			}
		}
		all.addAll(error);
		all.addAll(other);
		return all;
	}

	public List<Information> getAllInformation(Staff staff) {
		List<Information> list = null;
		int gid = Integer.parseInt(staff.getCompetence().getGroupId());
		if(gid == 0){
			list = informationDao.getInformationList("from Information", null);
		}else{
			list = this.getInformation(staff.getInfo());
		}
		return list;
	}

	public InformationDao getInformationDao() {
		return informationDao;
	}

	public void setInformationDao(InformationDao informationDao) {
		this.informationDao = informationDao;
	}
	
}
